/**
 * fileName:  FruitNutritionWriter.java
 * author:  huaimi
 * Company:  Cloudland Studio
 * Createdate:  2014-6-9 下午9:46:08
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-9          huaimi            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.FruitNutritionEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.NutritionRelationEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.NutritionRelationMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Component;

 /**
 * 水果与营养关系的dao操作持久化类，提供对对持久化方法的实现
 * @ClassName  FruitNutritionWriter
 * @author  huaimi
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Component
public class FruitNutritionWriter   implements DatabaseWrite<FruitNutritionEntity>
{
	@Resource(name="nutritionRelationMapper")
	private NutritionRelationMapper nutritionRelationMapper;
	
	/**
	 * 
	 * 批量保存水果与营养的关系
	 *
	 * @param fruitNutritionEntityList 水果与营养的关系集合
	 * @return 保存影响的行数
	 */
	public Integer batchInsertNutritionRelation(List<FruitNutritionEntity> fruitNutritionEntityList)
	{
		Integer result = 0;
		List<NutritionRelationEntity> entitys = new ArrayList<NutritionRelationEntity>(fruitNutritionEntityList.size());
		NutritionRelationEntity entity  = null;
		for (FruitNutritionEntity temp : fruitNutritionEntityList)
		{
			entity = new NutritionRelationEntity();
			entity.setCalculate(temp.getCalculate());
			entity.setFruitId(temp.getFruitId());
			entity.setFruitNutritionId(Randoms.uuid());
			entity.setNutritionId(temp.getNutritionId());
			entity.setNutritionScalar(temp.getNutritionScalar());
			entity.setNutritionType(Integer.valueOf(temp.getNutritionType().code()));
			entity.setSort(temp.getSort());
			
			entitys.add(entity);
		}
		
		result = nutritionRelationMapper.addBatch(entitys);
		return result;
	}
	
	/**
	 * <pre>
	 * 根据水果编号删除营养信息
	 * </pre>
	 *
	 * @param fruitId
	 * @return   
	 */
	public void deleteByFruitId(String fruitId)
	{
		nutritionRelationMapper.deleteByFruitId(fruitId);
	}

	/**
	 * @param entity
	 */
	public void save(FruitNutritionEntity entity) {
	}

	/**
	 * @param entity
	 */
	public void update(FruitNutritionEntity entity) {
	}

	/**
	 * @param entity
	 */
	public void delete(FruitNutritionEntity entity) {
	}
	

}
